
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>遍历二叉树和线索二叉树 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="树和森林.html" />
    
    
    <link rel="prev" href="二叉树的二叉链表实现.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    数据结构（C语言版） 复习总结
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../chapter1.html">
            
                <a href="../chapter1.html">
            
                    
                    第一章 绪论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../chapter2/chapter2.html">
            
                <a href="../chapter2/chapter2.html">
            
                    
                    第二章 线性表
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../chapter2/顺序表.html">
            
                <a href="../chapter2/顺序表.html">
            
                    
                    线性表的顺序表示和实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../chapter2/链表.html">
            
                <a href="../chapter2/链表.html">
            
                    
                    线性表的链式表示和实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../chapter3/chapter3.html">
            
                <a href="../chapter3/chapter3.html">
            
                    
                    第三章 栈和队列
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../chapter3/栈.html">
            
                <a href="../chapter3/栈.html">
            
                    
                    抽象数据类型栈的定义和实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../chapter3/队列.html">
            
                <a href="../chapter3/队列.html">
            
                    
                    抽象数据类型队列的定义和实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    第四章 串
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../chapter4/串类型.html">
            
                <a href="../chapter4/串类型.html">
            
                    
                    串类型的定义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../chapter4/串的表示和实现.html">
            
                <a href="../chapter4/串的表示和实现.html">
            
                    
                    串的表示和实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../chapter4/串的模式匹配算法.html">
            
                <a href="../chapter4/串的模式匹配算法.html">
            
                    
                    串的模式匹配算法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    第五章 数组和广义表
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../chapter5/数组的定义.html">
            
                <a href="../chapter5/数组的定义.html">
            
                    
                    数组的定义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../chapter5/矩阵的压缩存储.html">
            
                <a href="../chapter5/矩阵的压缩存储.html">
            
                    
                    矩阵的压缩存储
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../chapter5/广义表.html">
            
                <a href="../chapter5/广义表.html">
            
                    
                    广义表
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <span>
            
                    
                    第六章 树和二叉树
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="树.html">
            
                <a href="树.html">
            
                    
                    树的定义与基本术语
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="二叉树.html">
            
                <a href="二叉树.html">
            
                    
                    二叉树
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.2.1" data-path="二叉树的二叉链表实现.html">
            
                <a href="二叉树的二叉链表实现.html">
            
                    
                    二叉树的二叉链表实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter active" data-level="1.7.3" data-path="遍历二叉树和线索二叉树.html">
            
                <a href="遍历二叉树和线索二叉树.html">
            
                    
                    遍历二叉树和线索二叉树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="树和森林.html">
            
                <a href="树和森林.html">
            
                    
                    树和森林
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="赫夫曼树.html">
            
                <a href="赫夫曼树.html">
            
                    
                    赫夫曼树
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" >
            
                <span>
            
                    
                    第七章 图
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../chapter7/图.html">
            
                <a href="../chapter7/图.html">
            
                    
                    图的定义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../chapter7/图的存储结构.html">
            
                <a href="../chapter7/图的存储结构.html">
            
                    
                    图的存储结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../chapter7/图的遍历.html">
            
                <a href="../chapter7/图的遍历.html">
            
                    
                    图的遍历
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../chapter7/最小生成树.html">
            
                <a href="../chapter7/最小生成树.html">
            
                    
                    最小生成树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../chapter7/有向无环图.html">
            
                <a href="../chapter7/有向无环图.html">
            
                    
                    有向无环图的应用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../chapter8/查找.html">
            
                <a href="../chapter8/查找.html">
            
                    
                    第八章 查找
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../chapter8/静态查找表.html">
            
                <a href="../chapter8/静态查找表.html">
            
                    
                    静态查找表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../chapter8/动态查找表.html">
            
                <a href="../chapter8/动态查找表.html">
            
                    
                    动态查找表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../chapter8/哈希表.html">
            
                <a href="../chapter8/哈希表.html">
            
                    
                    哈希表
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../chapter9/内部排序.html">
            
                <a href="../chapter9/内部排序.html">
            
                    
                    第九章 内部排序
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../chapter9/插入排序.html">
            
                <a href="../chapter9/插入排序.html">
            
                    
                    插入排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../chapter9/选择排序.html">
            
                <a href="../chapter9/选择排序.html">
            
                    
                    选择排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../chapter9/快速排序.html">
            
                <a href="../chapter9/快速排序.html">
            
                    
                    快速排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../chapter9/归并排序和基数排序.html">
            
                <a href="../chapter9/归并排序和基数排序.html">
            
                    
                    归并排序和基数排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../chapter9/排序方法的比较.html">
            
                <a href="../chapter9/排序方法的比较.html">
            
                    
                    排序方法的比较
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >遍历二叉树和线索二叉树</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x904D;&#x5386;&#x4E8C;&#x53C9;&#x6811;">&#x904D;&#x5386;&#x4E8C;&#x53C9;&#x6811;</h2>
<p><strong>&#x904D;&#x5386;&#x4E8C;&#x53C9;&#x6811;</strong>&#x5373;&#x6309;&#x7167;&#x67D0;&#x6761;&#x641C;&#x7D22;&#x8DEF;&#x5F84;&#x8BBF;&#x95EE;&#x6811;&#x4E2D;&#x7684;&#x6BCF;&#x4E2A;&#x7ED3;&#x70B9;&#xFF0C;&#x4F7F;&#x5F97;&#x6BCF;&#x4E2A;&#x7ED3;&#x70B9;&#x5747;&#x88AB;&#x8BBF;&#x95EE;&#x4E00;&#x6B21;&#xFF0C;&#x800C;&#x4E14;&#x4EC5;&#x88AB;&#x8BBF;&#x95EE;&#x4E00;&#x6B21;&#x3002;&#x82E5;&#x9650;&#x5B9A;&#x5148;&#x5DE6;&#x540E;&#x53F3;&#xFF0C;&#x5219;&#x53EA;&#x6709; 3 &#x79CD;&#x60C5;&#x51B5;&#xFF0C;&#x5206;&#x522B;&#x79F0;&#x4E4B;&#x4E3A;&#x5148;&#xFF08;&#x6839;&#xFF09;&#x904D;&#x5386;&#x3001;&#x4E2D;&#xFF08;&#x6839;&#xFF09;&#x5E8F;&#x904D;&#x5386;&#x548C;&#x540E;&#xFF08;&#x6839;&#xFF09;&#x5E8F;&#x904D;&#x5386;&#x3002;</p>
<pre><code class="lang-C"><span class="hljs-comment">/**
 * &#x5148;&#x5E8F;&#x904D;&#x5386;
 * &#x9996;&#x5148;&#x8BBF;&#x95EE;&#x6839;&#x8282;&#x70B9;&#xFF0C;&#x63A5;&#x7740;&#x904D;&#x5386;&#x5DE6;&#x5B50;&#x6811;&#xFF0C;&#x6700;&#x540E;&#x904D;&#x5386;&#x53F3;&#x5B50;&#x6811;&#x3002; 
 */</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">PreOrder</span><span class="hljs-params">(BiTree root)</span>
</span>{
    <span class="hljs-keyword">if</span> (BiTreeEmpty(root) == <span class="hljs-number">0</span>) <span class="hljs-comment">// &#x5224;&#x65AD;&#x4E8C;&#x53C9;&#x6811;&#x662F;&#x5426;&#x4E3A;&#x7A7A;</span>
    {
        <span class="hljs-keyword">return</span>; <span class="hljs-comment">// &#x4E8C;&#x53C9;&#x6811;&#x4E3A;&#x7A7A;&#xFF0C;&#x5219;&#x904D;&#x5386;&#x7ED3;&#x675F;</span>
    }
    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;%c&quot;</span>, root-&gt;data); <span class="hljs-comment">// &#x8F93;&#x51FA;&#x6839;&#x8282;&#x70B9; </span>
    PreOrder(root-&gt;lchild);   <span class="hljs-comment">// &#x904D;&#x5386;&#x5DE6;&#x5B50;&#x6811; </span>
    PreOrder(root-&gt;rchild);   <span class="hljs-comment">// &#x904D;&#x5386;&#x53F3;&#x5B50;&#x6811; </span>
}

<span class="hljs-comment">/**
 * &#x4E2D;&#x5E8F;&#x904D;&#x5386;
 * &#x9996;&#x5148;&#x904D;&#x5386;&#x5DE6;&#x5B50;&#x6811;&#xFF0C;&#x63A5;&#x7740;&#x8BBF;&#x95EE;&#x6839;&#x8282;&#x70B9;&#xFF0C;&#x6700;&#x540E;&#x904D;&#x5386;&#x53F3;&#x5B50;&#x6811;&#x3002; 
 */</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">InOrder</span><span class="hljs-params">(BiTree root)</span>
</span>{
    <span class="hljs-keyword">if</span> (BiTreeEmpty(root) == <span class="hljs-number">0</span>) <span class="hljs-comment">// &#x5224;&#x65AD;&#x4E8C;&#x53C9;&#x6811;&#x662F;&#x5426;&#x4E3A;&#x7A7A;</span>
    {
        <span class="hljs-keyword">return</span>;
    }
    InOrder(root-&gt;lchild);    <span class="hljs-comment">// &#x904D;&#x5386;&#x5DE6;&#x5B50;&#x6811; </span>
    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;%c&quot;</span>, root-&gt;data); <span class="hljs-comment">// &#x8F93;&#x51FA;&#x6839;&#x8282;&#x70B9; </span>
    InOrder(root-&gt;rchild);    <span class="hljs-comment">// &#x904D;&#x5386;&#x53F3;&#x5B50;&#x6811; </span>
}

<span class="hljs-comment">/**
 * &#x540E;&#x5E8F;&#x904D;&#x5386;
 * &#x9996;&#x5148;&#x904D;&#x5386;&#x5DE6;&#x5B50;&#x6811;&#xFF0C;&#x63A5;&#x7740;&#x904D;&#x5386;&#x53F3;&#x5B50;&#x6811;&#xFF0C;&#x6700;&#x540E;&#x8BBF;&#x95EE;&#x6839;&#x8282;&#x70B9;
 */</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">PostOrder</span><span class="hljs-params">(BiTree root)</span>
</span>{
    <span class="hljs-keyword">if</span> (BiTreeEmpty(root) == <span class="hljs-number">0</span>) <span class="hljs-comment">// &#x5224;&#x65AD;&#x4E8C;&#x53C9;&#x6811;&#x662F;&#x5426;&#x4E3A;&#x7A7A;</span>
    {
        <span class="hljs-keyword">return</span>;
    } 
    PostOrder(root-&gt;lchild);  <span class="hljs-comment">// &#x904D;&#x5386;&#x5DE6;&#x5B50;&#x6811; </span>
    PostOrder(root-&gt;rchild);  <span class="hljs-comment">// &#x904D;&#x5386;&#x53F3;&#x5B50;&#x6811; </span>
    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;%c&quot;</span>, root-&gt;data); <span class="hljs-comment">// &#x8F93;&#x51FA;&#x6839;&#x7ED3;&#x70B9; </span>
}
</code></pre>
<blockquote>
<p>&#x5982;&#x679C;&#x4E8C;&#x53C9;&#x6811;&#x4E2D;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x6839;&#x7ED3;&#x70B9;&#xFF0C;&#x5219;&#x4E0D;&#x7BA1;&#x91C7;&#x7528;&#x4EC0;&#x4E48;&#x6837;&#x7684;&#x904D;&#x5386;&#x7B97;&#x6CD5;&#xFF0C;&#x6240;&#x5F97;&#x8BBF;&#x95EE;&#x5E8F;&#x5217;&#x90FD;&#x662F;&#x4E00;&#x6837;&#x7684;&#x3002;</p>
</blockquote>
<p><strong>&#x4E8C;&#x53C9;&#x6811;&#x7684;&#x524D;&#x5E8F;&#x904D;&#x5386;&#x975E;&#x9012;&#x5F52;&#x7B97;&#x6CD5;&#x7684;&#x57FA;&#x672C;&#x601D;&#x60F3;</strong></p>
<p>&#x5EFA;&#x7ACB;&#x4E00;&#x4E2A;&#x6808; S&#xFF0C;&#x5F53;&#x6307;&#x9488;&#x5230;&#x8FBE;&#x6839;&#x7ED3;&#x70B9;&#x65F6;&#xFF0C;&#x6253;&#x5370;&#x6839;&#x7ED3;&#x70B9;&#xFF0C;&#x5224;&#x65AD;&#x6839;&#x7ED3;&#x70B9;&#x662F;&#x5426;&#x6709;&#x5DE6;&#x5B69;&#x5B50;&#x548C;&#x53F3;&#x5B69;&#x5B50;&#xFF0C;&#x6709;&#x5DE6;&#x5B69;&#x5B50;&#x548C;&#x53F3;&#x5B69;&#x5B50;&#x7684;&#x8BDD;&#x5C31;&#x6253;&#x5370;&#x5DE6;&#x5B69;&#x5B50;&#x540C;&#x65F6;&#x5C06;&#x53F3;&#x5B69;&#x5B50;&#x5165;&#x6808;&#xFF0C;&#x5C06;&#x5DE6;&#x5B69;&#x5B50;&#x4F5C;&#x4E3A;&#x65B0;&#x7684;&#x6839;&#x7ED3;&#x70B9;&#x8FDB;&#x884C;&#x5224;&#x65AD;&#xFF0C;&#x65B9;&#x6CD5;&#x540C;&#x4E0A;&#x3002;&#x82E5;&#x5F53;&#x524D;&#x7ED3;&#x70B9;&#x6CA1;&#x6709;&#x5DE6;&#x5B69;&#x5B50;&#xFF0C;&#x5219;&#x76F4;&#x63A5;&#x5C06;&#x53F3;&#x5B69;&#x5B50;&#x6253;&#x5370;&#xFF0C;&#x540C;&#x65F6;&#x5C06;&#x53F3;&#x5B69;&#x5B50;&#x4F5C;&#x4E3A;&#x65B0;&#x7684;&#x6839;&#x7ED3;&#x70B9;&#x5224;&#x65AD;&#x3002;&#x82E5;&#x5F53;&#x524D;&#x7ED3;&#x70B9;&#x6CA1;&#x6709;&#x53F3;&#x5B69;&#x5B50;&#xFF0C;&#x5219;&#x6253;&#x5370;&#x5DE6;&#x5B69;&#x5B50;&#xFF0C;&#x540C;&#x65F6;&#x5C06;&#x5DE6;&#x5B69;&#x5B50;&#x4F5C;&#x4E3A;&#x65B0;&#x7684;&#x6839;&#x7ED3;&#x70B9;&#x5224;&#x65AD;&#x3002;&#x82E5;&#x5F53;&#x524D;&#x7ED3;&#x70B9;&#x65E2;&#x6CA1;&#x6709;&#x5DE6;&#x5B69;&#x5B50;&#x4E5F;&#x6CA1;&#x6709;&#x53F3;&#x5B69;&#x5B50;&#xFF0C;&#x5219;&#x5F53;&#x524D;&#x7ED3;&#x70B9;&#x4E3A;&#x53F6;&#x5B50;&#x7ED3;&#x70B9;&#xFF0C;&#x6B64;&#x65F6;&#x5C06;&#x4ECE;&#x6808;&#x4E2D;&#x51FA;&#x6808;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;&#x4F5C;&#x4E3A;&#x5F53;&#x524D;&#x7684;&#x6839;&#x7ED3;&#x70B9;&#xFF0C;&#x6253;&#x5370;&#x7ED3;&#x70B9;&#x5143;&#x7D20;&#xFF0C;&#x540C;&#x65F6;&#x5C06;&#x5F53;&#x524D;&#x7ED3;&#x70B9;&#x540C;&#x6837;&#x6309;&#x4E0A;&#x8FF0;&#x65B9;&#x6CD5;&#x5224;&#x65AD;&#xFF0C;&#x4F9D;&#x6B21;&#x8FDB;&#x884C;&#x3002;&#x76F4;&#x81F3;&#x5F53;&#x524D;&#x7ED3;&#x70B9;&#x7684;&#x5DE6;&#x53F3;&#x5B50;&#x90FD;&#x4E3A;&#x7A7A;&#xFF0C;&#x4E14;&#x6808;&#x4E3A;&#x7A7A;&#x65F6;&#xFF0C;&#x904D;&#x5386;&#x7ED3;&#x675F;&#x3002;</p>
<pre><code class="lang-C"><span class="hljs-comment">/**
 * &#x975E;&#x9012;&#x5F52;&#x65B9;&#x5F0F;&#x5148;&#x5E8F;&#x904D;&#x5386;&#x4E8C;&#x53C9;&#x6811;&#x3002;
 */</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">PreOrderTraverse</span><span class="hljs-params">(Bitree T)</span>
</span>{
    Initstack(S); <span class="hljs-comment">// &#x521D;&#x59CB;&#x5316;&#x5806;&#x6808;</span>
    BiTree p = T;
    While ( p || !stackEmpty(S)) <span class="hljs-comment">// &#x5F53;&#x6808;&#x4E0D;&#x4E3A;&#x7A7A;&#xFF0C;&#x5F53;&#x524D;&#x7ED3;&#x70B9;&#x4E0D;&#x4E3A;&#x7A7A;&#x65F6;&#xFF0C;&#x6267;&#x884C;&#x5FAA;&#x73AF;&#x4F53;</span>
    {
        <span class="hljs-keyword">if</span> (p)
        {
            visit(p-&gt;data);
             push(S,p); <span class="hljs-comment">// &#x8BB0;&#x4F4F;&#x8BE5;&#x7ED3;&#x70B9;</span>
             p = p-&gt;lchild; <span class="hljs-comment">// &#x6307;&#x5411;&#x5176;&#x5DE6;&#x5B50;&#x7ED3;&#x70B9;&#xFF0C;&#x8FDB;&#x884C;&#x904D;&#x5386;</span>
        }
        <span class="hljs-keyword">else</span>
        {
             pop(S,p); <span class="hljs-comment">// &#x56DE;&#x5230;&#x4E0A;&#x4E00;&#x7ED3;&#x70B9;</span>
             p = p-&gt;rchild; <span class="hljs-comment">// &#x6307;&#x5411;&#x5176;&#x53F3;&#x5B50;&#x7ED3;&#x70B9;&#xFF0C;&#x8FDB;&#x884C;&#x904D;&#x5386;</span>
        }
    }
}
</code></pre>
<p>&#x5BF9;&#x4E8E;&#x8868;&#x8FBE;&#x5F0F; <em>a+b&#xD7;(c-d)-e&#xF7;f</em> &#x53EF;&#x4EE5;&#x5EFA;&#x7ACB;&#x5982;&#x4E0B;&#x4E8C;&#x53C9;&#x6811;&#xFF1A;</p>
<center><img src="&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x4E8C;&#x53C9;&#x6811;.png"></center>

<p>&#x904D;&#x5386;&#x6B64;&#x4E8C;&#x53C9;&#x6811;&#xFF0C;&#x53EF;&#x4EE5;&#x5F97;&#x5230;</p>
<ul>
<li>&#x5148;&#x5E8F;&#x904D;&#x5386;&#x5F97;&#x5230;&#x524D;&#x7F00;&#x8868;&#x8FBE;&#x5F0F;&#xFF08;&#x6CE2;&#x5170;&#x5F0F;&#xFF09;&#xFF1A;<em>-+a&#xD7;b-cd&#xF7;ef</em></li>
<li>&#x79CD;&#x5E8F;&#x904D;&#x5386;&#x5F97;&#x5230;&#x4E2D;&#x7F00;&#x8868;&#x8FBE;&#x5F0F;&#xFF08;&#x539F;&#x5F0F;&#xFF09;&#xFF1A;<em>a+b&#xD7;(c-d)-e&#xF7;f</em></li>
<li>&#x5148;&#x5E8F;&#x904D;&#x5386;&#x5F97;&#x5230;&#x540E;&#x7F00;&#x8868;&#x8FBE;&#x5F0F;&#xFF08;&#x9006;&#x6CE2;&#x5170;&#x5F0F;&#xFF09;&#xFF1A;<em>abcd-&#xD7;+ef&#xF7;-</em></li>
</ul>
<p><strong>&#x5C42;&#x5E8F;&#x904D;&#x5386;</strong></p>
<p>&#x4ECE;&#x4E0A;&#x5230;&#x4E0B;&#x3001;&#x4ECE;&#x5DE6;&#x5230;&#x53F3;&#x6309;&#x5C42;&#x6B21;&#x8FDB;&#x884C;&#x904D;&#x5386;&#x3002;</p>
<h2 id="&#x7EBF;&#x7D22;&#x4E8C;&#x53C9;&#x6811;">&#x7EBF;&#x7D22;&#x4E8C;&#x53C9;&#x6811;</h2>
<p>&#x524D;&#x9A71;&#x4E0E;&#x540E;&#x7EE7;&#xFF1A;&#x5728;&#x4E8C;&#x53C9;&#x6811;&#x7684;&#x5148;&#x5E8F;&#x3001;&#x4E2D;&#x5E8F;&#x6216;&#x540E;&#x5E8F;&#x904D;&#x5386;&#x5E8F;&#x5217;&#x4E2D;&#x4E24;&#x4E2A;&#x76F8;&#x90BB;&#x7684;&#x7ED3;&#x70B9;&#x4E92;&#x79F0;&#x4E3A;<strong>&#x524D;&#x9A71;</strong>&#x4E0E;<strong>&#x540E;&#x7EE7;</strong>&#x3002;</p>
<p>&#x7EBF;&#x7D22;&#xFF1A;&#x6307;&#x5411;&#x524D;&#x9A71;&#x6216;&#x540E;&#x7EE7;&#x7ED3;&#x70B9;&#x7684;&#x6307;&#x9488;&#x79F0;&#x4E3A;<strong>&#x7EBF;&#x7D22;</strong>&#x3002;</p>
<p>&#x7EBF;&#x7D22;&#x4E8C;&#x53C9;&#x6811;&#xFF1A;&#x52A0;&#x4E0A;&#x7EBF;&#x7D22;&#x7684;&#x4E8C;&#x53C9;&#x94FE;&#x8868;&#x8868;&#x793A;&#x7684;&#x4E8C;&#x53C9;&#x6811;&#x53EB;<strong>&#x7EBF;&#x7D22;&#x4E8C;&#x53C9;&#x6811;</strong>&#x3002;</p>
<p>&#x7EBF;&#x7D22;&#x5316;&#xFF1A;&#x5BF9;&#x4E8C;&#x53C9;&#x6811;&#x6309;&#x67D0;&#x79CD;&#x904D;&#x5386;&#x6B21;&#x5E8F;&#x4F7F;&#x5176;&#x53D8;&#x4E3A;&#x7EBF;&#x7D22;&#x4E8C;&#x53C9;&#x6811;&#x7684;&#x8FC7;&#x7A0B;&#x53EB;<strong>&#x7EBF;&#x7D22;&#x5316;</strong>&#x3002;</p>
<p>&#x5229;&#x7528;&#x4E8C;&#x53C9;&#x94FE;&#x8868;&#x4E2D;&#x5B58;&#x5728;&#x7684;&#x7A7A;&#x94FE;&#x57DF;&#x5B58;&#x653E;&#x7ED3;&#x70B9;&#x7684;&#x524D;&#x9A71;&#x4E0E;&#x540E;&#x7EE7;&#x7684;&#x4FE1;&#x606F;&#xFF0C;&#x56E0;&#x6B64;&#x505A;&#x4EE5;&#x4E0B;&#x89C4;&#x5B9A;&#xFF1A;&#x82E5;&#x7ED3;&#x70B9;&#x6709;&#x5DE6;&#x5B50;&#x6811;&#xFF0C;&#x5219;&#x5176; <em>lchild</em> &#x57DF;&#x6307;&#x793A;&#x5176;&#x5DE6;&#x5B69;&#x5B50;&#xFF0C;&#x5426;&#x5219;&#x4EE4; <em>lchild</em> &#x6307;&#x793A;&#x5176;&#x524D;&#x9A71;&#xFF1B;&#x82E5;&#x7ED3;&#x70B9;&#x6709;&#x53F3;&#x5B50;&#x6811;&#xFF0C;&#x5219;&#x5176; <em>rchild</em> &#x57DF;&#x6307;&#x793A;&#x5176;&#x53F3;&#x5B69;&#x5B50;&#xFF0C;&#x5426;&#x5219;&#x4EE4; <em>rchild</em> &#x57DF;&#x6307;&#x793A;&#x5176;&#x540E;&#x7EE7;&#x3002;&#x4E3A;&#x6B64;&#xFF0C;&#x6539;&#x53D8;&#x7ED3;&#x70B9;&#x7ED3;&#x6784;&#xFF0C;&#x589E;&#x52A0;&#x4E86;&#x4E24;&#x4E2A;&#x6807;&#x5FD7;&#x57DF; <em>LTag</em> &#x548C; <em>RTag</em>&#x3002;</p>
<blockquote>
<p>&#x6807;&#x5FD7;&#x57DF;&#x4E3A; 1 &#x8868;&#x793A;&#x6307;&#x793A;&#x524D;&#x9A71;&#x6216;&#x540E;&#x7EE7;&#xFF1B;&#x6807;&#x5FD7;&#x57DF;&#x4E3A; 0 &#x8868;&#x793A;&#x6307;&#x793A;&#x5DE6;&#x3001;&#x53F3;&#x5B69;&#x5B50;&#x3002;</p>
</blockquote>
<p>&#x4EE5;&#x8FD9;&#x79CD;&#x7ED3;&#x70B9;&#x7ED3;&#x6784;&#x6784;&#x6210;&#x7684;&#x4E8C;&#x53C9;&#x94FE;&#x8868;&#x4F5C;&#x4E3A;&#x4E8C;&#x53C9;&#x6811;&#x7684;&#x5B58;&#x50A8;&#x7ED3;&#x6784;&#xFF0C;&#x53EB;&#x505A;<strong>&#x7EBF;&#x7D22;&#x94FE;&#x8868;</strong>&#x3002;&#x5176;&#x4E2D;&#xFF0C;&#x6307;&#x5411;&#x7ED3;&#x70B9;&#x524D;&#x9A71;&#x548C;&#x540E;&#x7EE7;&#x7684;&#x6307;&#x9488;&#xFF0C;&#x53EB;&#x505A;<strong>&#x7EBF;&#x7D22;</strong>&#x3002;&#x52A0;&#x4E0A;&#x7EBF;&#x7D22;&#x7684;&#x4E8C;&#x53C9;&#x6811;&#x53EB;&#x505A;<strong>&#x7EBF;&#x7D22;&#x4E8C;&#x53C9;&#x6811;</strong>&#x3002;&#x5BF9;&#x4E8C;&#x53C9;&#x6811;&#x7684;&#x67D0;&#x79CD;&#x6B21;&#x5E8F;&#x904D;&#x5386;&#x4F7F;&#x5176;&#x53D8;&#x4E3A;&#x7EBF;&#x7D22;&#x4E8C;&#x53C9;&#x6811;&#x7684;&#x8FC7;&#x7A0B;&#x53EB;&#x505A;<strong>&#x7EBF;&#x7D22;&#x5316;</strong>&#x3002;</p>
<p>&#x5728;&#x7EBF;&#x7D22;&#x6811;&#x4E0A;&#x8FDB;&#x884C;&#x904D;&#x5386;&#xFF0C;&#x53EA;&#x8981;&#x5148;&#x627E;&#x5230;&#x5E8F;&#x5217;&#x4E2D;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x7ED3;&#x70B9;&#xFF0C;&#x7136;&#x540E;&#x4F9D;&#x6B21;&#x627E;&#x7ED3;&#x70B9;&#x540E;&#x7EE7;&#x76F4;&#x81F3;&#x5176;&#x540E;&#x7EE7;&#x4E3A;&#x7A7A;&#x65F6;&#x800C;&#x81F3;&#x3002;</p>
<p>&#x6839;&#x636E;&#x4E2D;&#x5E8F;&#x904D;&#x5386;&#x7684;&#x89C4;&#x5F8B;&#x53EF;&#x77E5;&#xFF0C;&#x7ED3;&#x70B9;&#x7684;&#x540E;&#x7EE7;&#x662F;&#x904D;&#x5386;&#x5176;&#x53F3;&#x5B50;&#x6811;&#x65F6;&#x8BBF;&#x95EE;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x7ED3;&#x70B9;&#xFF0C;&#x5373;&#x53F3;&#x5B50;&#x6811;&#x4E2D;&#x6700;&#x5DE6;&#x4E0B;&#x7684;&#x7ED3;&#x70B9;&#x3002;&#x5728;&#x4E2D;&#x5E8F;&#x7EBF;&#x7D22;&#x6811;&#x4E2D;&#x627E;&#x7ED3;&#x70B9;&#x524D;&#x9A71;&#x7684;&#x89C4;&#x5F8B;&#x662F;&#xFF1A;&#x82E5;&#x5176;&#x5DE6;&#x6807;&#x5FD7;&#x4E3A;&#x201C;1&#x201D;&#xFF0C;&#x5219;&#x5DE6;&#x94FE;&#x4E3A;&#x7EBF;&#x7D22;&#xFF0C;&#x6307;&#x793A;&#x5176;&#x524D;&#x9A71;&#xFF0C;&#x5426;&#x5219;&#x904D;&#x5386;&#x5DE6;&#x5B50;&#x6811;&#x65F6;&#x6700;&#x540E;&#x8BBF;&#x95EE;&#x7684;&#x4E00;&#x4E2A;&#x7ED3;&#x70B9;&#xFF08;&#x5DE6;&#x5B50;&#x6811;&#x4E2D;&#x6700;&#x53F3;&#x4E0B;&#x7684;&#x7ED3;&#x70B9;&#xFF09;&#x4E3A;&#x5176;&#x524D;&#x9A71;&#x3002;</p>
<p><strong>&#x4E8C;&#x53C9;&#x6811;&#x7684;&#x4E8C;&#x53C9;&#x7EBF;&#x7D22;&#x5B58;&#x50A8;&#x8868;&#x793A;</strong></p>
<pre><code class="lang-C"><span class="hljs-keyword">typedef</span> <span class="hljs-keyword">enum</span> PointerTag <span class="hljs-comment">// Link == 0 &#x8868;&#x793A;&#x6307;&#x9488;&#xFF1B;Thread == 1 &#x8868;&#x793A;&#x7EBF;&#x7D22;</span>
{
    Link,Thread
};

<span class="hljs-keyword">typedef</span> <span class="hljs-keyword">struct</span> BiThrNode
{
    ElemType data;
    <span class="hljs-keyword">struct</span> BiThrNode *lchild, *rchild; <span class="hljs-comment">// &#x5DE6;&#x3001;&#x53F3;&#x5B69;&#x5B50;&#x6307;&#x9488;</span>
    PointerTag LIag, RTag; <span class="hljs-comment">// &#x5DE6;&#x3001;&#x53F3;&#x6807;&#x5FD7;</span>
}
</code></pre>
<blockquote>
<p>&#x5728;&#x4E8C;&#x53C9;&#x6811;&#x7684;&#x7EBF;&#x7D22;&#x94FE;&#x8868;&#x4E0A;&#x4E5F;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x5934;&#x7ED3;&#x70B9;&#xFF0C;&#x5E76;&#x4EE4;&#x5176; <em>lchild</em> &#x57DF;&#x7684;&#x6307;&#x9488;&#x6307;&#x5411;&#x4E8C;&#x53C9;&#x6811;&#x7684;&#x6839;&#x8282;&#x70B9;&#xFF0C;&#x5176; <em>rchild</em> &#x57DF;&#x7684;&#x6307;&#x9488;&#x6307;&#x5411;&#x4E2D;&#x5E8F;&#x904D;&#x5386;&#x65F6;&#x8BBF;&#x95EE;&#x7684;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x7ED3;&#x70B9;&#x3002;&#x4EE4;&#x4E8C;&#x53C9;&#x6811;&#x4E2D;&#x5E8F;&#x5E8F;&#x5217;&#x4E2D;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x7ED3;&#x70B9;&#x7684; <em>lchild</em> &#x57DF;&#x6307;&#x9488;&#x548C;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x7ED3;&#x70B9;&#x7684; <em>rchild</em> &#x57DF;&#x7684;&#x6307;&#x9488;&#x5747;&#x6307;&#x5411;&#x5934;&#x7ED3;&#x70B9;&#x3002;</p>
</blockquote>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="二叉树的二叉链表实现.html" class="navigation navigation-prev " aria-label="Previous page: 二叉树的二叉链表实现">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="树和森林.html" class="navigation navigation-next " aria-label="Next page: 树和森林">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"遍历二叉树和线索二叉树","level":"1.7.3","depth":2,"next":{"title":"树和森林","level":"1.7.4","depth":2,"path":"chapter6/树和森林.md","ref":"chapter6/树和森林.md","articles":[]},"previous":{"title":"二叉树的二叉链表实现","level":"1.7.2.1","depth":3,"path":"chapter6/二叉树的二叉链表实现.md","ref":"chapter6/二叉树的二叉链表实现.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"chapter6/遍历二叉树和线索二叉树.md","mtime":"2018-08-24T03:05:06.148Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-09-02T10:05:33.540Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

